package com.atguigu.spzx.manager.controller;

import com.atguigu.spzx.log.annation.SpzxLog;
import com.atguigu.spzx.manager.service.BrandService;
import com.atguigu.spzx.model.common.Result;
import com.atguigu.spzx.model.entity.brand.Brand;
import com.github.pagehelper.PageInfo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * title:
 * author: zgl
 * date: 2024/1/3
 * description：
 */
@RestController
@RequestMapping("/admin/product/brand")
@Tag(name = "品牌管理模块")
public class BrandController {
    @Autowired
    private BrandService brandService;

    @GetMapping("/brandList/{pageNum}/{pageSize}")
    @Operation(summary = "品牌列表分页查询")
    public Result getBrandList(
            @PathVariable Integer pageNum,
            @PathVariable Integer pageSize) {
        PageInfo<Brand> pageInfo = brandService.getBrandList(pageNum, pageSize);
        return Result.ok(pageInfo);
    }

    @GetMapping("/getBrandById/{id}")
    @Operation(summary = "id查询品牌接口")
    public Result getBrandById(@PathVariable Long id) {
        Brand brand = brandService.getBrandById(id);
        return Result.ok(brand);
    }

    @DeleteMapping("/deletedBrand/{id}")
    @Operation(summary = "品牌删除接口")
    @SpzxLog(title = "品牌管理模块")
    public Result deletedBrand(@PathVariable Long id) {
        brandService.deletedBrand(id);
        return Result.ok();
    }

    @PutMapping("/updateBrand")
    @Operation(summary = "品牌修改接口")
    public Result deletedBrand(@RequestBody Brand brand) {
        brandService.updateBrand(brand);
        return Result.ok();
    }

    @PostMapping("/saveBrand")
    @Operation(summary = "品牌添加接口")
    public Result saveBrand(@RequestBody Brand brand) {
        brandService.saveBrand(brand);
        return Result.ok();
    }

    @GetMapping("/list")
    @Operation(summary = "查询所有品牌列表")
    public Result list() {
        List<Brand> list = brandService.list();
        return Result.ok(list);
    }
}
